package kandl.automation.steprunner.selenium.commands;


import kandl.automation.steprunner.selenium.Command;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.springframework.stereotype.Component;

@Component
class ScrollToElement implements Command {
    @Override
    public void runCommand(WebDriver driver, String... params) {
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("window.scrollBy(0, document.body.scrollHeight)");
		js.executeScript("window.scrollBy(0, -400)");
        driver.findElement(By.xpath(params[0])).click();
    }

    @Override
    public String getName() {
        return "scrollToElement";
    }
}